<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CheckUser</title>
</head>
<script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
	function ine(data) {

		if (data == 1) {
			document.getElementById("checkUN").innerHTML = "<b style='color: red'>用户名已存在</b>";
		} else if (data == 2) {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>不能为空</b>";
		} else if (data == 3) {
			document.getElementById("checkUN").innerHTML = "<b style='color:green'>该用户名可用</b>"
		} else if (data == 0) {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>ajax成功返回值为空</b>"
		} else {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>未知错误</b>"
		}
	}

	function checkUser() {
		var name = $('#userName').val();
		var s = 0;
		$.ajax({
			type : "post",
			url : '${pageContext.request.contextPath}/user/checkUser.action',
			data : "name=" + name,
			success : function(data) {
				ine(data);
			}
		});

	}

	$(document).ready(function() {
		$("#userName").blur(function() {
			checkUser();
		});
	})
</script>
<body>

	用户名 :
	<input type="text" name="userName" id="userName">
	<span id="checkUN"></span>

</body>
</html>